﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace QQSDK
{
    public class ToolsSample : SDKBaseSample
    {
        private string captureImageName = "test_image.png";
        public void Vibrator()
        {
            ToolsManager.Vibrator(2);
        }
        public void ShareInstagram()
        {
            ScreenCapture.CaptureScreenshot(captureImageName, 2);
            string path = System.IO.Path.Combine(Application.persistentDataPath, captureImageName);
            if (!System.IO.File.Exists(path))
            {
                ToolsManager.ShowToast("文件不存在");
            }
            ToolsManager.ShareInstagram(this.gameObject.name, "ShareInstagramCallback", path);
        }
        void ShareInstagramCallback(string message)
        {
            SDKFunc.Log("======返回的代码:" + message);
            string result = string.Empty;
            switch (message)
            {
                case "0":
                    result = "分享成功";
                    break;
                case "1":
                    result = "请先安装instagram，才能使用此功能";
                    break;
                case "2":
                    result = "路径错误，文件错误";
                    break;
            }
#if UNITY_EDITOR || DEVELOP
            SDKFunc.Log("======结果:" + result);
#elif UNITY_IOS && !DELSDK
        SDKFunc.Log("======结果:" + result);
#elif UNITY_ANDROID
        ToolsManager.ShowToast("=====结果:" + result);
#endif
        }
        public void SendEmail()
        {
            ToolsManager.SendEmail(this.gameObject.name, "SendEMailCallback", "lovin0996korla@.gmail", "主题", "test_project");
        }
        void SendEMailCallback(string msg)
        {
            SDKFunc.Log("======返回的结果：" + msg);
        }
        public void ShareMoreInLocal()
        {
            ScreenCapture.CaptureScreenshot(captureImageName, 2);
            string path = System.IO.Path.Combine(Application.persistentDataPath, captureImageName);
            if (!System.IO.File.Exists(path))
            {
                ToolsManager.ShowToast("文件不存在");
            }
            ToolsManager.ShareNative(this.gameObject.name, "ShareMoreInLocalCallback", path, "");
        }
        void ShareMoreInLocalCallback(string msg)
        {
            SDKFunc.Log("返回的代码：" + msg);
            if (msg.Equals("0"))
            {
                SDKFunc.LogError("分享成功");
            }
            else if (msg.Equals("2"))
            {
                SDKFunc.LogError("分享失败，文件或路径错误");
            }
        }
        public void CopyTextToClipboard()
        {
            string msg = "测试粘贴板";
            ToolsManager.CopyTextToClipboard(msg);
        }
        public void CheckAndroidPermission()
        {
            if (ToolsManager.CheckAndroidPermission("android.permission.WRITE_EXTERNAL_STORAGE"))
            {
                ToolsManager.ShowToast("已经拥有本地存储权限");
            }
            else
            {
                ToolsManager.ShowToast("未拥有本地存储权限");
            }
        }
        public void RequestAndroidPermission()
        {
            if (ToolsManager.CheckAndroidPermission("android.permission.WRITE_EXTERNAL_STORAGE"))
            {
                ToolsManager.ShowToast("已经拥有本地存储权限，不需要再进行请求");
            }
            else
            {
                ToolsManager.RequestAndroidPermission("android.permission.WRITE_EXTERNAL_STORAGE");
            }
        }
        public void IsIphoneXAboveDivice()
        {
            SDKFunc.LogError("是否为刘海平手机" + ToolsManager.IsIphoneXAboveDivice());
        }
        public void SaveVideo()
        {
            string captureImageName = "test_image.png";
            ScreenCapture.CaptureScreenshot(captureImageName, 2);
            string path = System.IO.Path.Combine(Application.persistentDataPath, captureImageName);
            ToolsManager.SaveMedia(this.gameObject.name, "SaveMediaCallback", path, MediaType.Picture);
        }
        void SaveMediaCallback(string msg)
        {

            if (msg.Equals("0"))
            {
                SDKFunc.LogError("====保存成功");
            }
            else if (msg.Equals("2"))
            {
                SDKFunc.LogError("======保存失败，文件或路径错误");
            }
        }
        public void CopyFile()
        {

        }
     
        public void IsAppInstall()
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
        SDKFunc.Log("=======是否安装App：" + ToolsManager.IsAppInstall("color.by.number.diamond.sequins.art.picture"));
#elif UNITY_ANDROID
        ToolsManager.ShowToast("是否安装app:" + ToolsManager.IsAppInstall("color.by.number.diamond.sequins.art.picture"));
#endif
        }
        public void GetChannelName()
        {
            ToolsManager.ShowToast("GetChannelName为：" + ToolsManager.GetChannelName());
        }
        public void GetManifestValue()
        {
            ToolsManager.ShowToast("获取清单文件值为：" + ToolsManager.ReadValueFromManifest("CHANNEL_NAME"));
        }
        public void GetVerName()
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
        SDKFunc.LogError("======获取应用的版本名称" + QQSDK.ToolsManager.GetVerName());
#elif UNITY_ANDROID
        ToolsManager.ShowToast("获取应用的版本名称 :" + QQSDK.ToolsManager.GetVerName());
#endif
        }
        public void GetVersionCode()
        {
#if UNITY_EDITOR || DEVELOP

#elif UNITY_IOS && !DELSDK
        SDKFunc.LogError("======获取应用的版本名称" + QQSDK.ToolsManager.GetVerCode());
#elif UNITY_ANDROID
        ToolsManager.ShowToast(" 获取应用的版本号 :" + QQSDK.ToolsManager.GetVerCode());
#endif

        }
        public void DownloadPromotionUrl()
        {
            ToolsManager.DownLoadAndroidApk("http://game3cn.tapque.com/colorpaint/apk/paintColor_20200313_test_02.apk");
        }
        public void RequestIosCameraPermission()
        {
            ToolsManager.RequestAppleCameraPermission(this.gameObject.name, "PermissionCallbcak");
        }
        public void RequestIosAlbumPermission()
        {
            ToolsManager.RequestAppleAblumPermission(this.gameObject.name, "PermissionCallbcak");
        }
        void PermissionCallbcak(string msg)
        {
            SDKFunc.Log("PermissionCallbcak======"+ msg);
            if (msg.Equals("0"))
            {
                SDKFunc.Log("======成功获取权限");
            }
            else if (msg.Equals("2"))
            {
                SDKFunc.Log("=====用户拒绝权限");
            }
        }
        public void RequestIosIDFAPermission()
        {
            ToolsManager.RequestIDFAPermission(this.gameObject.name, "PermissionCallbcak");
        }

        public void ShowGDPR()
        {
            ToolsManager.ShowGDPR("http://file.cdn.tapque.com/Innovate/Makeup/Makeup_Privacy_policy.html");
        }

        public void IsDebugOrRelease()
        {
            ToolsManager.ShowToast("当前发布的是Debug还是Release :" + ToolsManager.IsDebugOrRelease());
           
        }


        public void JumpToCommentChina()
        {
            ToolsManager.JumpToComment(true);
        }


        public void JumpToCommentGPAndIOSShop()
        {
            ToolsManager.JumpToComment();
        }

        bool isAddCallBack = false;
        public void BuyProduct()
        {
            if (isAddCallBack == false)
            {
                isAddCallBack = true;
                SDKFunc.Log("加载回调");
                QQSDK.SDKManager.onPayResultMessageCallback += (attribution) =>
                {
                    SDKFunc.Log("BuyProduct:" + attribution.state + ",product_id:" + attribution.product_id);
                };
            }


#if UNITY_EDITOR || DEVELOP
            QQSDK.SDKManager.PurchaseVerification_IOS("com.pay.iap10", "1552222222", "transactionID", @"{""Payload"":""MIIXCQYJKoZIhvcNAQcCoIIW +j*********************QCAQEEAgwAMAscFgpAG/CFZ801Wui/"",""Store"":""AppleAppStore"",""TransactionID"":""2000000311393160""}", "Default", "");
#elif UNITY_IOS
           QQSDK.SDKManager.PurchaseVerification_IOS("com.pay.iap10","1552222222", "transactionID", "*******************", "Default", "");
#elif UNITY_ANDROID
           QQSDK.SDKManager.PurchaseVerification_Android("small_diamonds", "iap购买成功的返回值", 1);
#else
#endif


        }



        //public void AbtestInit()
        //{

        //    List<string> ablist = new List<string>();
        //    ablist.Add("sdk_test_01");
        //    ablist.Add("sdk_test_02");
        //    StartCoroutine(SDKManager.instance.InitConfig(ablist));

        //}



        public void AbtestGet()
        {

            string test_abvalue = SDKManager.GetABTest("sdk_test_01");
            SDKFunc.Log("abtest sdk_test_01 :" + test_abvalue);


            //if(SDKManager.ConfigIsInit)
            //{
            //    string test_abvalue = SDKManager.GetABTest("sdk_test_01");


            //    SDKFunc.Log("abtest sdk_test_01 :" + test_abvalue);
            //}
            //else
            //{
            //    SDKFunc.Log("abtest sdk_test_01 : no init s");
            //}

        }

    }
}